import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;


public class LoginForm extends JFrame {

	private JPanel contentPane;
	private JTextField uid;
	private JTextField pwd;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LoginForm frame = new LoginForm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LoginForm() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 418, 252);
		contentPane = new JPanel();
		setResizable(false);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		setLocationRelativeTo(null);
		
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				JFrame j = (JFrame)e.getSource();
				int choice = JOptionPane.showConfirmDialog(null, "프로그램을 종료 하시겠어요?","JoinOn",JOptionPane.YES_NO_OPTION);
				if(choice == JOptionPane.YES_NO_OPTION)
					j.setDefaultCloseOperation(EXIT_ON_CLOSE);
			}
		});
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		
		JLabel txtUid = new JLabel("아이디 :");
		
		JLabel iconLogo = new JLabel("로고");
		
		uid = new JTextField();
		uid.setColumns(10);
		
		JLabel txtPwd = new JLabel("비밀번호 :");
		
		pwd = new JTextField();
		pwd.setColumns(10);
		
		JButton btnCheck = new JButton("확인");
		
		JLabel memJoin = new JLabel("회원가입");
		
		memJoin.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				MemJoinForm mjf = new MemJoinForm();
				mjf.setVisible(true);
			}
		});
		
		JLabel separator = new JLabel("|");
		
		JLabel findUid = new JLabel("아이디를 잃어 버리셨나요?");
		
		JLabel findPwd = new JLabel("비밀번호를 잃어 버리셨나요?");
		GroupLayout gl_panel = new GroupLayout(panel);
		
		btnCheck.addActionListener(new Check());
		
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
					.addContainerGap(59, Short.MAX_VALUE)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(87)
							.addComponent(iconLogo))
						.addGroup(gl_panel.createSequentialGroup()
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addComponent(txtUid, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE)
								.addComponent(txtPwd))
							.addGap(18)
							.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
								.addComponent(uid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(pwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addComponent(btnCheck))
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(44)
							.addComponent(memJoin)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(separator)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addComponent(findPwd, GroupLayout.PREFERRED_SIZE, 184, GroupLayout.PREFERRED_SIZE)
								.addComponent(findUid))))
					.addGap(37))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(28)
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
						.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
							.addGap(32)
							.addComponent(btnCheck, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
						.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
							.addComponent(iconLogo)
							.addGap(18)
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panel.createSequentialGroup()
									.addComponent(txtUid)
									.addGap(18)
									.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
										.addComponent(txtPwd)
										.addComponent(pwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
								.addComponent(uid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addGap(18)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(memJoin)
						.addComponent(separator)
						.addComponent(findUid))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(findPwd)
					.addContainerGap(54, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
	}
	
	private class Check implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {
			String mUid = uid.getText();
			String mPwd = pwd.getText();
			if(mUid.equals("") || mPwd.equals(""))
				JOptionPane.showConfirmDialog(null, "아이디와 비밀번호를 입력해주세요.","JoinOn",JOptionPane.DEFAULT_OPTION);
		}
		
	}
}
